/*
 * OPIAM Suite
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package opiam.admin.faare.persistence;

import opiam.admin.faare.service.UserContext;

import java.util.ArrayList;
import java.util.Iterator;


/**
*
*  Class which implements the Collection interface and the lazy loading model.
*/
public abstract class LazyCollection
{
    /**
     * Creates a new LazyCollection object.
     *
     * @param enclosing Dname of entry containing attribute being loaded.
     * @param atts Name of attribute being loaded.
     * @param userContext User context.
     */
    public LazyCollection(String enclosing, ArrayList atts,
        UserContext userContext)
    {
    }

    /**
     * Gets identifiers of elements in collections.
     *
     * @return List of identifiers.
     */
    public abstract ArrayList getIdentitiesList();

    /**
     * Gets number of elements in collection.
     *
     * @return Number of elements.
     */
    public abstract int size();

    //DW/2553/BeginPatch
    /**
     * Gets an iterator on collection items.
     *
     * @return Iterator.
     */
    public abstract Iterator iterator();

    /**
     * Displays collection.
     *
     * @return String formatted collection
     * Same format as Collection : "[value1,...,valuen]"
     */
    @Override
	public String toString()
    {
        StringBuffer buf = new StringBuffer();
        Iterator e = iterator();
        buf.append("[");

        int maxIndex = size() - 1;

        for (int i = 0; i <= maxIndex; i++)
        {
            try
            {
                buf.append(String.valueOf(e.next()));
            }
            catch (Exception ex)
            {
                ex.printStackTrace();
            }

            if (i < maxIndex)
            {
                buf.append(", ");
            }
        }

        buf.append("]");

        return buf.toString();
    }

    //DW/2553/EndPatch
}
